package com.example.demo2_review.thread_safe_gather;

import java.util.*;

/**
 * @Author zwp14
 * @create 2024/6/18 15:35
 * @description 线程安全的Set-TreeSet和LinkedHashSet
 */
public class TreeSetAndLinkedHashSet {
    public static void main(String[] args) {
        Set<String> treeSet = new TreeSet<>();
        treeSet.add("value1");
        treeSet.add("calue2");
        treeSet.add("aalue3");
        treeSet.add("balue3");//将会进行去重，只保留一个value3
        System.out.println("treeSet = " + treeSet);
        List<String> integerList = new ArrayList<>();
        integerList.add("2");
        integerList.add("4");
        integerList.add("3");
        integerList.add("1");
        treeSet.addAll(integerList);
        System.out.println("treeSet = " + treeSet);//从小到大，从a-z自然排序


        Set<Integer> linkedHashSet = new LinkedHashSet<>(3);
        List<Integer> stringList = new ArrayList<>();
        stringList.add(2);
        stringList.add(4);
        stringList.add(3);
        stringList.add(1);
        linkedHashSet.addAll(stringList);
        System.out.println("linkedHashSet = " + linkedHashSet);//按照插入顺序排序
    }
}
